<template>
  <a-table
    :columns="columns"
    :data-source="tableData"
    :pagination="false"
    :scroll="{ x: 1500 }"
  >
    <span slot="logisticsName" slot-scope="text, record">
      <a-icon
        type="check-circle"
        style="color: #3eae7c"
        v-if="record.sign === '1'"
      />
      <a-icon
        type="close-circle"
        style="color: #f5222d"
        v-if="record.sign === '0'"
      />
      {{ record.logisticsName }}
    </span>
    <span slot="auditState" slot-scope="text, record">
      <span v-if="record.auditState != '正在处理'">{{
        record.auditState
      }}</span>
      <span v-if="record.auditState == '正在处理' && record.isSendBill == null">
        未发送账单
      </span>
      <span v-if="record.auditState == '正在处理' && record.isSendBill != null">
        已发送账单
      </span>
    </span>
    <span
      slot="applyState"
      slot-scope="text, record"
      :style="
        record.applyState === '暂缓处理'
          ? 'color:#ff9933'
          : record.applyState === '异常订单'
          ? 'color:#F3381D'
          : 'color:#3eae7c'
      "
    >
      {{ record.applyState }}
    </span>
    <span
      slot="action"
      class="action"
      slot-scope="text, record"
      :fixed="'right'"
    >
      <a
        slot="action"
        href="javascript:;"
        @click="eidtRow(record, 'info', 'look')"
        v-if="['等待处理', '正在处理', '已转运发货'].includes(TransferOutKeys)"
        >订单详情</a
      >
      <a-popconfirm
        title="确定删除该条数据吗?"
        ok-text="确定"
        cancel-text="取消"
        @confirm="deleteRow(record)"
        v-if="['待提交', '审核不通过'].includes(TransferOutKeys)"
      >
        <a href="javascript:;">删除订单</a>
      </a-popconfirm>
    </span>
  </a-table>
</template>

<script>
import {
  TransferOut_del,
  TransferOut_submit,
  TransferOut_recallt,
} from "@/apis/clientSide/OrderManage/TransferOut";
export default {
  props: [
    "tableData",
    "TransferOutKeys",
    "getTransferOutTableList",
    "getStateCount",
  ],
  data() {
    return {
      SKUTablieData: [],
    };
  },
  created() {},
  methods: {
    //编辑每一行
    eidtRow(rowData, flag, auditState) {
      setTimeout(() => {
        this.$bus.$emit("TransferOutRowData", rowData, flag, auditState);
      }, 50);
    },
    //删除每一行
    async deleteRow(record) {
      let { code } = await TransferOut_del(record.key);
      if (code === "10000") {
        this.getTransferOutTableList();
        this.getStateCount();
      }
    },
    submitData(record, flag) {
      let _this = this;
      if (flag === "submit") {
        this.$confirm({
          title: "确认提交该订单吗?",
          cancelText: "取消",
          okText: "确认",
          onOk() {
            return new Promise((resolve) => {
              setTimeout(async () => {
                let { code } = await TransferOut_submit(
                  `${record.key}/${record.revision}`
                );
                if (code === "10000") {
                  resolve();
                }
              }, 1000);
            }).then(() => {
              _this.getTransferOutTableList();
              _this.getStateCount();
            });
          },
        });
      } else if (flag === "withdraw") {
        this.$confirm({
          title: "确认撤回该订单吗?",
          cancelText: "取消",
          okText: "确认",
          onOk() {
            return new Promise((resolve) => {
              setTimeout(async () => {
                let { code } = await TransferOut_recallt(record.key);
                if (code === "10000") {
                  resolve();
                }
              }, 1000);
            }).then(() => {
              _this.getTransferOutTableList();
              _this.getStateCount();
            });
          },
        });
      }
    },
  },
  computed: {
    columns() {
      return [
        {
          title: "客户编号",
          dataIndex: "tenantId",
          align: "center",
          width: "8%",
          ellipsis: true,
        },
        {
          title: "转运仓库",
          dataIndex: "warehouseName",
          align: "center",
          width: "8%",
          ellipsis: true,
        },
        {
          title: "转运出库编号",
          dataIndex: "transferNo",
          align: "center",
          // scopedSlots: { customRender: "selfClassifyName" },
          ellipsis: true,
          width: "8%",
        },
        {
          title: "转运标题",
          dataIndex: "title",
          align: "center",
          width: "12%",
          ellipsis: true,
        },
        {
          title: "FBA ID",
          dataIndex: "fbaId",
          // ellipsis: true,
          scopedSlots: { customRender: "fbaId" },
          align: "center",
          width: "10%",
        },
        {
          title: "Reference ID",
          dataIndex: "referenceId",
          //   scopedSlots: { customRender: "waybillNo" },
          align: "center",
          width: "10%",
          ellipsis: true,
        },
        {
          title: "目的地公司",
          dataIndex: "companyTitle",
          //   scopedSlots: { customRender: "logistics_cost" },
          align: "center",
          width: "10%",
          ellipsis: true,
        },
        {
          title: "状态",
          dataIndex: "auditState",
          scopedSlots: { customRender: "auditState" },
          align: "center",
          width: "10%",
          ellipsis: true,
        },
        {
          title: "创建时间",
          dataIndex: "createTime",
          //   scopedSlots: { customRender: "createTime" },
          align: "center",
          width: "12%",
          ellipsis: true,
        },
        {
          title: "操作",
          dataIndex: "action",
          scopedSlots: { customRender: "action" },
          align: "center",
          width: 200,
          fixed: "right",
        },
      ];
    },
  },
};
</script>

<style lang="less" scoped>
.action {
  a {
    border-bottom: 1px solid rgb(41, 41, 224);
    color: rgb(41, 41, 224);
  }
}
</style>
